/*
 * =====================================================================================
 *
 *       Filename:  kuohao.c
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  06/14/2011 11:12:47 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (), 
 *        Company:  
 *
 * =====================================================================================
 */

#include <stdio.h>
#include <string.h>
#include "sqstack.h"

int main(int argc, char **argv)
{
    int ret = 0;
    sqstack stack;
    sqstack *pStack = &stack; 
    memset(pStack, 0, sizeof(sqstack));
    printf("1\n");
    ret = init_stack(pStack);
    printf("2\n");
    int c_input; 
    int tmp;
    while((c_input = fgetc(stdin)) != EOF)
    {
        if (c_input == '\n')
            continue;

        printf("you input %d\n", c_input);
        if (stack_is_empty(pStack))
        {
            printf("stack is empty\n");
            push(pStack, c_input);
            continue;
        }

        pop(pStack, &tmp);
        printf("pop is %d\n", tmp);
        if (((tmp == '(') && (c_input == ')')) || ((tmp == '[') && (c_input == ']')))
        {
            printf("priv %d, next %d\n", tmp, c_input);
            continue;
        }
        push(pStack, tmp);
        push(pStack, c_input);
        display(pStack);
        c_input = 0;
    }
    return 0;
}

